<!--
 * @FileDescription 标定主页
 * @Author lz
 * @Date 20230223 13:33:39
 * @LastEditors lz
 * @LastEditTime 20230223 13:33:39
-->
<template>
    <div class="wp">
        <!-- 顶部 -->
        <hdrModel Hierarchy="2" :ID="0"></hdrModel>
        <div class="times" v-if="HomeContent.Default.itemType.value == '考核'">
            {{ TM(state.times) }}
        </div>
        <div class="Btn" @click="submit()" v-if="HomeContent.Default.itemType.value == '考核'">
            提交
        </div>
        <!-- 标定列表 -->
        <!-- <demarcateList></demarcateList> -->
        <!-- 视角导航 -->
        <perspectiveList></perspectiveList>
        <!-- 工具栏 -->
        <!-- <toolbarList></toolbarList> -->
        <!-- 教学辅助 -->
        <teachingAids v-if="HomeContent.Default.itemType.value == '教学'"></teachingAids>
        <teachingAids></teachingAids>

    <div class="skip_l">
        <!-- <img src="/structure/jlgd_ico.png" class="skip_ico" @click="show()"> -->
        <p class="titName">记录工单</p>
    </div>


    <!-- <div class="skip_Box">
            <div class="skip_l">
                <img src="/structure/jlgd_ico.png" class="skip_ico" @click="show()">
                <p class="titName">记录工单</p>
            </div>
                                        <div class="lines">
                                        </div>
                                        <div class="skip_r">
                                            <img src="/structure/bdsm_ico.png" class="skip_ico">
                                            <p class="titName">标定说明</p>
                                        </div>
                                    </div> -->
        <div class="to_top" v-if="HomeContent.Default.MouseLabel.value != ''">{{ HomeContent.Default.MouseLabel.value }}
        </div>
        <colContent></colContent>
        <colChange></colChange>
    </div>
</template>

<script setup lang="ts">
import hdrModel from '../header/index.vue'
import demarcateList from '../demarcateMenu/model/demarcateList.vue'
import perspectiveList from '../demarcateMenu/model/perspectiveList.vue'
import { reactive, ref, toRefs, onBeforeMount, onMounted, onBeforeUpdate, onUpdated, onUnmounted, StyleValue, defineProps, defineEmits, watch } from 'vue'
import colContent from '../colRecordSheet/index.vue'
import colChange from '../colChange/index.vue'
import HomeContent from '../HomeContent'
import { message } from 'ant-design-vue'
import { ClientMessage } from '@runtime/generate/message/ClientMessage'
import WebSocketComponent from '@runtime/module/WebSocket/WebSocketComponent'
import teachingAids from '../demarcateMenu/model/teachingAids.vue'
import { useRouter } from 'vue-router'
import MessageCode from '../MessageCode'
const state = reactive({
    timer: 0,  // 定时器对象
    times: 0,  //用时毫秒数
});
//监听提示推送
watch(() => HomeContent.Default.pointOutTypes.value, (newVal, oldVal) => {
    if (newVal != oldVal) {
        message.warning(HomeContent.Default.pointOut.value);
    }
})
function show() {
    HomeContent.Default.WorkOrderShow.value = true
}
let MouseLabelX = ref('0%')
let MouseLabelY = ref('0%')
let newXY: any = {}
let refNum = ref(0)
function requestCoordinate() {
    newXY = JSON.parse(window.sessionStorage.getItem('Cursor')!)
    MouseLabelX.value = (newXY.X * window.screen.width * 0.01) + 10 + 'px'
    MouseLabelY.value = (newXY.Y * window.screen.height * 0.01) + 10 + 'px'
    refNum.value = requestAnimationFrame(requestCoordinate)
}
const router = useRouter()

//提交
function submit() {
    let tim = state.times / 1000
    WebSocketComponent.Default.PostMessageAsync(new ClientMessage.CalibrationAdapterRequest(MessageCode.Default.MsgCodesList.APPRAISE_SUBMIT, `${tim}`))


    if (HomeContent.Default.ApplicationType.value == '标定') {
        router.push('demarcatePage')
    } else if (HomeContent.Default.ApplicationType.value == '拆装') {
        router.push('summaryPage')
    }
}
//时间转
function TM(ms: number) {
    let h: string | number = Math.floor(ms / 1000 / 60 / 60)
    let m: string | number = Math.floor(ms / 1000 / 60)
    let s: string | number = Math.floor(ms / 1000)

    if (h === 1) {
        // 当时间刚好是60分钟时，让它以mm:ss格式显示,即显示60:00,而不是显示01:00:00
        if (m / 60 === 1 && s % 60 === 0) {
            h = ''
            m = '60:'
        } else {
            h = '01:'
            m = addZero(m % 60) + ':'
        }
        s = addZero(s % 60)
    } else {
        h = h === 0 ? '' : addZero(h) + ':'
        m = addZero(m % 60) + ':'
        s = addZero(s % 60)
    }
    return h + m + s
}
// 进行补0操作
function addZero(n: string | number) {
    return n < 10 ? '0' + n : n
}
onMounted(() => {
    //计时
    state.timer = window.setInterval(() => {
        state.times += 1000
        if (state.times == 36000000) {
            clearInterval(state.timer);
            state.timer = 0;
        }
    }, 1000);
    refNum.value = requestAnimationFrame(requestCoordinate)
})
onUnmounted(() => {
    window.cancelAnimationFrame(refNum.value)
})
</script>

<style scoped>
.wp {
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    position: relative;
}

.skip_Box {
    position: absolute;
    left: 0;
    top: 910px;
    width: 290px;
    height: 143px;
    background-image: url('/structure/jxfz_bg.png');
    background-repeat: no-repeat;
    background-size: 100% 100%;
    display: flex;
    text-align: center;
}

.to_top {
    font-size: 20px;
    text-align: center;
    position: absolute;
    color: #fff;
    left: v-bind(MouseLabelX);
    top: v-bind(MouseLabelY);
    padding: 5px 10px;
    background: rgba(13, 20, 59, 0.36);
    border: 1px solid rgba(53, 196, 255, 0.34);
}

.skip_l {
    position: absolute;
    right: 40px;
    bottom: 20px;
    text-align: center;
    /* width: 50%; */
}

.skip_r {
    width: 50%;
}

.skip_ico {
    width: 49px;
    height: 54px;
    margin-top: 26px;
}

.titName {
    font-size: 16px;
    font-weight: 400;
    color: #FFFFFF;
    margin-top: 10px;
}

.lines {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    height: 50px;
    width: 1px;
    background-color: rgba(255, 255, 255, 0.3);
}

.Btn {
    position: absolute;
    left: 75%;
    top: 16px;
    z-index: 999;
    font-size: 18px;
    text-align: center;
    color: #fff;
    font-weight: bold;
    line-height: 54px;
    width: 120px;
    height: 54px;
    background-image: url('/structure/btn_bg.png');
    background-repeat: no-repeat;
    background-size: 100% 100%;
    margin-top: -7px;
    margin-right: 10px;
}

.Btn:hover {
    color: #fff;
    background-image: url('/structure/btn_bg_select.png');
}

.times {
    position: absolute;
    left: 71%;
    top: 18px;
    float: left;
    line-height: 36px;
    font-size: 24px;
    font-weight: bold;
    color: #fff;
    margin-right: 10px;
}
</style>